package com.info33.platform.system.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.info33.platform.common.constant.TableConstant;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.system.dto.SysTenantUserDTO;
import com.info33.platform.system.entity.SysTenantUser;
import com.info33.platform.system.service.SysTenantUserService;
import com.info33.platform.system.vo.SysTenantUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysTenantUser")
@Api(tags = "系统 - 租户用户")
public class SysTenantUserController extends BaseController<SysTenantUserService, SysTenantUser> {

    private final SysTenantUserService sysTenantUserService;

    @Autowired
    public SysTenantUserController(SysTenantUserService sysTenantUserService) {
        super(sysTenantUserService);
        this.sysTenantUserService = sysTenantUserService;
    }

    @PutMapping(value = "/change/mainColor")
    @ApiOperation(value = "pc - 改变主题色")
    public Result<Object> changeMainColor(
            @Validated(value = SysTenantUserDTO.ChangeMainColor.class) @RequestBody SysTenantUserDTO dto) {
        return sysTenantUserService.update(new UpdateWrapper<SysTenantUser>()
                .set("main_color", dto.getMainColor())
                .eq(TableConstant.ID, getCurrentUser().getSysTenantUserVO().getId())) ? Result.ok() : Result.error();
    }

    @GetMapping(value = "/pc/li")
    @ApiOperation(value = "pc 用户下拉")
    public Result<List<SysTenantUserVO>> pcLi() {
        return sysTenantUserService.pcLi(getCurrentUser());
    }

}